package cn.liuhuan1.blogsModel.service;

import cn.liuhuan1.blogsModel.dao.AnswerDao;
import cn.liuhuan1.blogsModel.dao.LeaveWordDao;
import cn.liuhuan1.webModelBean.api.NaswerImp;
import cn.liuhuan1.webModelBean.bo.AnswerBo;
import cn.liuhuan1.webModelBean.vo.AnswerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Auther: liuhuan
 * @Date: 2021/4/5 - 04 - 05 - 3:13
 * @Description:
 * @version: 1.0
 */
@Service
public class AnswerService implements NaswerImp {

    @Autowired
    private AnswerDao answerDao;

    @Autowired
    private LeaveWordDao leaveWordDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveAnswer(AnswerBo naswerBo) {
        if(naswerBo == null || naswerBo.getLeaveWoedId() ==null){
            throw new NullPointerException();
        }
        answerDao.saveAnswer(naswerBo);
        leaveWordDao.updateStatus("1", naswerBo.getLeaveWoedId());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<AnswerVo> loadAnswerList(String leaveWoedId) {
        if(leaveWoedId == null || leaveWoedId.trim() == ""){
            throw new NullPointerException();
        }
        List<AnswerVo> answerVoList = answerDao.loadAnswerList(leaveWoedId);
        return answerVoList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delById(String id) {
        if(id == null || id.trim() == ""){
            throw new NullPointerException();
        }
        answerDao.delById(id);
    }
}
